package com.cysion.study.presenter

import com.cysion.study.ktbox.base.BasePresenter
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.other.addTo
import com.cysion.targetfun._subscribe
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.ui.iview.PendingView

class PendingPresenter :BasePresenter<PendingView>(){
    //待审批
    fun getList(curPage: Int, category: Int) {
        checkViewAttached()
        attchedView?.loading()
        ApiClient.api.getOwnDealList(UserCache.token,curPage, category)
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    attchedView?.stopLoad()
                    attchedView?.onGetPendingList(it)
                }
                _onError {
                    attchedView?.stopLoad()
                }
            }.addTo(compositeDisposable)
    }
    //已审批
    fun getDealedList(curPage: Int) {
        checkViewAttached()
        attchedView?.loading()
        ApiClient.api.getOwnDealedList(UserCache.token,curPage)
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    attchedView?.stopLoad()
                    attchedView?.onGetPendingList(it)
                }
                _onError {
                    attchedView?.stopLoad()
                }
            }.addTo(compositeDisposable)
    }

}
